"use strict";
cc._RF.push(module, 'fcda7AIIR1FE6bJb1xzUL9l', 'GameView');
// script/poker_project/gameView/GameView.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var UiUtils_1 = require("../base/UiUtils");
var ConfigEnum_1 = require("../ConfigEnum");
var UIPoker_1 = require("../UIPoker");
var GameDB_1 = require("./GameDB");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var GameScene = /** @class */ (function (_super) {
    __extends(GameScene, _super);
    function GameScene() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.pokerPrefab = null;
        _this.initPokerArea = null;
        _this.closeSendArea = null;
        _this.openSendArea = null;
        _this.receiveAreaList = [];
        _this.playGroupRoot = null;
        return _this;
    }
    // private playGroupList: cc.Node[] = [];
    GameScene.prototype.onLoad = function () {
        // for(let i = 0;i<GameDB.CONST_PLAY_GROUPS;i++){
        //     let playGroup = new cc.Node()
        //     playGroup.position = new cc.Vec3(85*i, 0, 0)
        //     this.playGroupRoot.addChild(playGroup)
        //     this.playGroupList.push(playGroup)
        // }
        //所有节点都放在同一个root下面
    };
    GameScene.prototype.OnPlay = function () {
        var stack = [];
        for (var i = this.initPokerArea.children.length - 1; i >= 0; i--) {
            var child = this.initPokerArea.children[i];
            stack.push(child);
            this.initPokerArea.removeChild(child);
        }
        for (var i = stack.length - 1; i >= 0; --i) {
            var child = stack[i];
            this.closeSendArea.addChild(child);
        }
    };
    GameScene.prototype.OnEventInit = function (pokers) {
        this.InitPokers(pokers);
    };
    GameScene.prototype.OnEventPlay = function () {
        console.log("OnPlay");
        this.OnPlay();
    };
    // private OnEventClickPoker (poker: Poker) {
    //     SplashScene.eventTarget.emit(GameEvent.CLICK_POKER,poker)
    //     console.log("OnClickPoker",poker)
    // }
    GameScene.prototype.InitPokers = function (pokers) {
        var _this = this;
        //展示所有扑克ui
        console.log("InitPokers");
        pokers.forEach(function (poker, index) {
            var uiPoker = _this.CreateUIPoker(poker);
            uiPoker.node.x = 0.2 * index;
            uiPoker.node.y = 0.2 * index;
            _this.initPokerArea.addChild(uiPoker.node);
        });
    };
    GameScene.prototype.CreateUIPoker = function (poker) {
        var uiPokerNode = cc.instantiate(this.pokerPrefab);
        var uiPoker = uiPokerNode.getComponent(UIPoker_1.default);
        uiPoker.Init(poker);
        // SplashScene.eventTarget.on(GameEvent.CLICK_POKER,this.OnEventClickPoker,this);
        return uiPoker;
    };
    GameScene.prototype.OnEventINitGroupCard = function (groupIndex, cardIndex, poker) {
        var index = GameDB_1.default.CONST_PLAY_GROUPS * cardIndex - cardIndex * (cardIndex + 1) / 2 - cardIndex + groupIndex;
        //    console.log(`g:${groupIndex} c:${cardIndex} p:${poker.point} index:${index}`)
        //先移动ui
        var node = poker.view.node;
        UiUtils_1.default.move(node, this.playGroupRoot);
        node.zIndex = index;
        //    let wp = node.convertToWorldSpaceAR(cc.v3(0,0,0))
        //    let gp = this.playGroupRoot.convertToNodeSpaceAR(wp)
        //    node.removeFromParent()
        //    node.position = gp;
        //    this.playGroupRoot.addChild(node,index)
        //    node.x = gp.x
        //    node.y = gp.y
        //    node.setSiblingIndex(index)
        var px = groupIndex * 85;
        var delay = index * 0.1;
        if (poker.status == ConfigEnum_1.EPokerStatus.OPEN) {
            cc.tween(node)
                .delay(delay)
                .to(0.5, { position: cc.v3(px, -30 * cardIndex) })
                .to(0.3, { scaleX: 0 })
                .call(function () {
                //ui的显示状态更新
                poker.view.Rrfresh();
            })
                .to(0.3, { scaleX: 1 })
                .start();
        }
        else {
            cc.tween(node)
                .delay(delay)
                .to(0.5, { position: cc.v3(px, -30 * cardIndex) })
                .start();
        }
    };
    __decorate([
        property(cc.Prefab)
    ], GameScene.prototype, "pokerPrefab", void 0);
    __decorate([
        property(cc.Node)
    ], GameScene.prototype, "initPokerArea", void 0);
    __decorate([
        property(cc.Node)
    ], GameScene.prototype, "closeSendArea", void 0);
    __decorate([
        property(cc.Node)
    ], GameScene.prototype, "openSendArea", void 0);
    __decorate([
        property([cc.Node])
    ], GameScene.prototype, "receiveAreaList", void 0);
    __decorate([
        property(cc.Node)
    ], GameScene.prototype, "playGroupRoot", void 0);
    GameScene = __decorate([
        ccclass
    ], GameScene);
    return GameScene;
}(cc.Component));
exports.default = GameScene;

cc._RF.pop();